// package com.nbgroup.controller;
//
//
// import com.google.code.kaptcha.impl.DefaultKaptcha;
// import com.nbgroup.pojo.common.CodeResult;
//
// import org.springframework.beans.factory.annotation.Autowired;
// import org.springframework.web.bind.annotation.GetMapping;
// import org.springframework.web.bind.annotation.RequestMapping;
// import org.springframework.web.bind.annotation.RestController;
//
// import javax.imageio.ImageIO;
// import javax.servlet.ServletOutputStream;
// import javax.servlet.http.HttpServletRequest;
// import javax.servlet.http.HttpServletResponse;
// import java.awt.image.BufferedImage;
// import java.io.ByteArrayOutputStream;
//
// /**
//  * @Author: ljh
//  * @ClassName VerificationCodeController
//  * @Description TODO
//  * @date 2022/11/3 20:25
//  * @Version 1.0
//  */
// @RestController
// //@Api(tags = "验证码管理")
// @RequestMapping("/code")
// public class VerificationCodeController {
//
//
//     @Autowired
//     private DefaultKaptcha captchaProducer;
//
//
//     //@ApiOperation("获取验证码图片")
//     @GetMapping("/getVerificationCodePhoto")
//     public void getVerificationCodePhoto(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws Exception {
//         byte[] captchaOutputStream = null;
//         ByteArrayOutputStream imgOutputStream = new ByteArrayOutputStream();
//         try {
//             //生成验证码
//             String verifyCode = captchaProducer.createText();
//             //验证码字符串保存到session中
//             httpServletRequest.getSession().setAttribute("verifyCode", verifyCode);
//             BufferedImage challenge = captchaProducer.createImage(verifyCode);
//             //设置写出图片的格式
//             ImageIO.write(challenge, "jpg", imgOutputStream);
//         } catch (IllegalArgumentException e) {
//             httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND);
//             return;
//         }
//         captchaOutputStream = imgOutputStream.toByteArray();
//         httpServletResponse.setHeader("Cache-Control", "no-store");
//         httpServletResponse.setHeader("Pragma", "no-cache");
//         httpServletResponse.setDateHeader("Expires", 0);
//         httpServletResponse.setContentType("image/jpeg");
//         ServletOutputStream responseOutputStream = httpServletResponse.getOutputStream();
//         responseOutputStream.write(captchaOutputStream);
//         responseOutputStream.flush();
//         responseOutputStream.close();
//     }
//
//
//    // @ApiOperation("获取验证码")
//     @GetMapping("/getVerificationCode")
//     public CodeResult getVerificationCode(HttpServletRequest request) {
//         CodeResult result = new CodeResult();
//         String verifyCode = captchaProducer.createText();
//         request.getSession().setAttribute("verifyCode", verifyCode);
//         result.setVerCode(verifyCode);
//         return result;
//
//     }
//
// }
